package 多线程.复习.线程常用属性;

public class ThreadAttr {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() ->{
            for (int i = 0; i < 2; i++) {
                System.out.println("线程ID" + Thread.currentThread().getId());
                System.out.println("线程名" +Thread.currentThread().getName());
                System.out.println("线程优先级"+Thread.currentThread().getPriority());
                System.out.println("线程状体"+Thread.currentThread().getState());
                System.out.println("后台线程 ？ "+Thread.currentThread().isDaemon());
                System.out.println("存活 ？"+Thread.currentThread().isAlive());
                System.out.println("被中断 ？" +Thread.currentThread().isInterrupted());
                try {
                    Thread.sleep(1000);
                    System.out.println("___________________________________");
                    System.out.println("睡眠线程状态"+Thread.currentThread().getState());
                    System.out.println("睡眠和后台线程 ？ "+Thread.currentThread().isDaemon());
                    System.out.println("睡眠和存活 ？"+Thread.currentThread().isAlive());
                    System.out.println("睡眠后被中断 ？" +Thread.currentThread().isInterrupted());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        thread.join();
        System.out.println("___________________________________");
        System.out.println("线程ID" + Thread.currentThread().getId());
        System.out.println("线程名" +Thread.currentThread().getName());
        System.out.println("线程优先级"+Thread.currentThread().getPriority());
        System.out.println("线程状体"+Thread.currentThread().getState());
        System.out.println("后台线程 ？ "+Thread.currentThread().isDaemon());
        System.out.println("存活 ？"+Thread.currentThread().isAlive());
        System.out.println("被中断 ？" +Thread.currentThread().isInterrupted());
    }
}
